<?php

namespace application\Module;

use library\Core\Db\CDbCriteria;
use application\Model\CommentModel;
use application\Comm\Func;

class Comment
{
    /**
     * @param $pid
     * @param array $select
     * @return array
     * 根据位置获取评论
     */
    public function getList($pid='', $select = ['id', 'name', 'description', 'url', 'src','num','username','like'])
    {
        $criteria = new CDbCriteria();
        $criteria->select($select);
        if ($pid != ''){
       	 $criteria->addEqCondition('position_id', $pid);
       	 $criteria->setLimit(3);
        }
        $criteria->addEqCondition('is_del', 0);
        $criteria->addEqCondition('status', 1);
        $criteria->addOrderDesc('orderby');
       
        $commentModel = new CommentModel();
        $data = $commentModel->getListForArray($criteria);
        if(!empty($data)){
            foreach($data as $k => $v){
                $data[$k]['src'] = Func::imgUrl($v['src']);
            }
        }
        return $data;
    }

    /**
     * @return array
     *
     */
    public function getLike($id)
    {
        $criteria = new CDbCriteria();
        $select = [
            'like',
        ];
        $criteria->select($select);
        $criteria->addEqCondition('id', $id);
        $criteria->addEqCondition('is_del', 0);
        $criteria->addEqCondition('status', 1);
        $commentModel = new CommentModel();
        return $commentModel->getOne($criteria);

    }

}
